from get_codes import *
from get_price import Get_price
import sys 
sys.path.append(r'code')
from data_capture.data_contrate import Data_consentrate
import shutil



get_etf_codes()

etf = pd.read_csv(r'data/etf_data/code_date/etf_codes.csv')
etf = etf['代码'].values

shutil.rmtree('data\etf_data\daily_price')
G = Get_price()
G.get_price(etf)


lst = ['open', 'high', 'low', 'close', 'volume', 'vol', 'lagret']
for i in lst:
    D = Data_consentrate(root=r'data/etf_data/daily_price', thred=300)
    D.consentrate(key=i)

def data_fliter():
    root = r'data\etf_data\consentrate_daily_price'
    lst = ['open', 'high', 'low', 'close', 'volume', 'vol', 'lagret']
    vol = pd.read_pickle(os.path.join(root, 'vol.pkl.gzip'))
    sortv = vol.mean().sort_values()
    sortv_id = sortv[sortv>0.01].index
    for i in lst:
        file = os.path.join(root,f'{i}.pkl.gzip')
        data_i = pd.read_pickle(file)
        data_i = data_i[sortv_id]
        data_i.to_pickle(file)

data_fliter()